home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / networke / xfirepow.000 / xfirepow / xfirepower-0.84 / client / redraw.c < prev    next >
C/C++ Source or Header  |  1996-03-16  |  8KB  |  371 lines

  1. #include <stdio.h>
  2. #include "Wlib.h"
  3. #include "data.h"
  4. #include "struct.h"
  5. #include "defs.h"
  6. #include "images.h"
  7.  
  8. int t_image_nums[NUMTERRAINS] = {
  9.     I_GRASS,
  10.     I_ROAD,
  11.     I_TREE,
  12.     I_POST,
  13.     I_POST,
  14.     I_WALL_T,
  15.     I_WALL_R,
  16.     I_WALL_TR,
  17.     I_WALL_B,
  18.     I_WALL_TB,
  19.     I_WALL_BR,
  20.     I_WALL_TBR,
  21.     I_WALL_L,
  22.     I_WALL_TL,
  23.     I_WALL_RL,
  24.     I_WALL_TRL,
  25.     I_WALL_BL,
  26.     I_WALL_TBL,
  27.     I_WALL_BRL,
  28.     I_WALL_TBRL,
  29.     I_WATER,
  30.     I_CRATER,
  31.     I_BASE1,
  32.     I_BASE2,
  33.     I_BRIDGE,
  34. };
  35.  
  36. void draw_local(int x, int y)
  37. {
  38.     int i,j;
  39.     W_Image *img;
  40.  
  41.     for(i=x/GRIDWIDTH; i<=(x/GRIDWIDTH+1) + WINWIDTH/GRIDWIDTH;i++) {
  42.     for(j=y/GRIDHEIGHT; j <= (y/GRIDHEIGHT+1) + WINHEIGHT/GRIDHEIGHT; j++) {
  43.         switch(map[i][j]) {
  44.           case T_TREE:
  45.         img = t_shapes[T_GRASS];
  46.         break;
  47.           case T_BASE1:
  48.           case T_BASE2:
  49.         img = t_shapes[T_ROAD];
  50.         break;
  51.           default:
  52.         img = t_shapes[(int)map[i][j]];
  53.         break;
  54.         }
  55.         W_DrawImageNoClip(cwin, i*GRIDWIDTH-x, j*GRIDHEIGHT-y, counter, img, W_Green);
  56.     }
  57.     }
  58. }
  59.  
  60. void draw_overlays(int x, int y)
  61. {
  62.     int i,j;
  63.  
  64.     for(i=x/GRIDWIDTH; i<=(x/GRIDWIDTH+1) + WINWIDTH/GRIDWIDTH;i++) {
  65.     for(j=y/GRIDHEIGHT; j <= (y/GRIDHEIGHT+1) + WINHEIGHT/GRIDHEIGHT; j++) {
  66.         switch(map[i][j]) {
  67.           case T_TREE:
  68.           case T_BASE1:
  69.           case T_BASE2:
  70.         W_DrawImage(cwin, i*GRIDWIDTH-x, j*GRIDHEIGHT-y, 0, t_shapes[(int)map[i][j]], W_Green);
  71.         break;
  72.           default:
  73.         break;
  74.         }
  75.     }
  76.     }
  77. }
  78.  
  79.  
  80. void draw_players(int cx, int cy)
  81. {
  82.     int dx, dy;
  83.     int i;
  84.     player *p;
  85.     W_Image *img;
  86.     W_Color color;
  87.     char buf[20];
  88.  
  89.     for(i=0,p=&players[0];i<MAXPLAYERS;i++,p++) {
  90.     if(p->p_status == PALIVE) {
  91.         dx = (p->p_x>>4) - cx - myTankImg->width/2;
  92.         dy = (p->p_y>>4) - cy - myTankImg->height/2;
  93.  
  94.         if(p == me) {
  95.         my_dx = dx + myTankImg->width/2;
  96.         my_dy = dy + myTankImg->width/2;
  97.         }
  98.  
  99.         if(dx>(-((int)myTankImg->width)) &&
  100.            dy >(-((int)myTankImg->height)) &&
  101.            dx < WINWIDTH &&
  102.            dy < WINHEIGHT) {
  103.         if(p == me)
  104.             img = myTankImg;
  105.         else
  106.             img = teamTankImg[(p->p_team == 0) ? 0 : 1];
  107.         W_DrawImage(cwin, dx, dy, (p->p_dir+8) >> 4, img, W_Cyan);
  108.         color = (p==me) ? W_White : W_Yellow;
  109.         if(namesOnTanks)
  110.             sprintf(buf, "%s(%d)", players[i].p_name, i);
  111.         else
  112.             sprintf(buf, "%d", i);
  113.         W_MaskText(cwin, dx + (myTankImg->width/2)-(strlen(buf)*W_Textwidth)/2, dy-W_Textheight, 
  114.                color, buf, strlen(buf), W_BoldFont);
  115.         }
  116.     } else if(p->p_expfuse > 0) {
  117.         dx = (p->p_x>>4) - cx - expImg->width/2;
  118.         dy = (p->p_y>>4) - cy - expImg->height/2;
  119.         if(dx>(-((int)expImg->width)) &&
  120.            dy >(-((int)expImg->height)) &&
  121.            dx < WINWIDTH &&
  122.            dy < WINHEIGHT) {
  123.         W_DrawImage(cwin, dx, dy, EXPFUSE - p->p_expfuse, expImg, W_Red);
  124.         }
  125.         p->p_expfuse--;
  126.     }
  127.     }
  128. }
  129.  
  130. void draw_shells(int cx, int cy)
  131. {
  132.     int dx, dy;
  133.     int i;
  134.     shell *s;
  135.     W_Image *img;
  136.  
  137.     for(i=0,s=&shells[0];i<SHELLSPERPLAYER * MAXPLAYERS;i++,s++) {
  138.     if(s->s_status == SALIVE) {
  139.         dx = (s->s_x>>4) - cx;
  140.         dy = (s->s_y>>4) - cy;
  141.         if(dx > 0 &&
  142.            dy > 0 &&
  143.            dx < WINWIDTH &&
  144.            dy < WINHEIGHT) {
  145.         img = shellImg;
  146.         W_DrawImage(cwin, dx - img->width/2, dy - img->height/2, s->s_fuse, img, W_Cyan);
  147.         } else
  148.         s->s_status = SDEAD;
  149.     }
  150.     }
  151. }
  152.  
  153. void draw_shell_exps(int cx, int cy)
  154. {
  155.     int dx, dy;
  156.     int i;
  157.     shell *s;
  158.     W_Image *img;
  159.  
  160.     for(i=0,s=&shells[0];i<SHELLSPERPLAYER * MAXPLAYERS;i++,s++) {
  161.     if(s->s_status == SEXPLODE) {
  162.         dx = (s->s_x>>4) - cx;
  163.         dy = (s->s_y>>4) - cy;
  164.         if(dx > 0 &&
  165.            dy > 0 &&
  166.            dx < WINWIDTH &&
  167.            dy < WINHEIGHT) {
  168.         img = mineExpImg;
  169.         W_DrawImage(cwin, dx - img->width/2, dy - img->height/2, s->s_fuse, img, W_Cyan);
  170.         s->s_fuse++;
  171.         if(s->s_fuse >= img->frames)
  172.             s->s_status = SDEAD;
  173.         } else
  174.         s->s_status = SDEAD;
  175.     }
  176.     }
  177. }
  178.  
  179. void draw_flags(int cx, int cy)
  180. {
  181.     int dx, dy;
  182.     int i;
  183.     flag *f;
  184.  
  185.     for(i=0,f=&flags[0];i<NUMFLAGS;i++,f++) {
  186.     dx = (f->f_x >> 4) - cx;
  187.     dy = (f->f_y >> 4) - cy;
  188.     if(dx > 0 &&
  189.        dy > 0 &&
  190.        dx < WINWIDTH &&
  191.        dy < WINHEIGHT)
  192.         W_DrawImage(cwin, dx - flagImg[f->f_team]->width/2, dy - flagImg[f->f_team]->height/2, 
  193.             0, flagImg[f->f_team], W_Cyan);
  194.     }
  195. }
  196.  
  197. void draw_mines(int cx, int cy)
  198. {
  199.     int dx, dy;
  200.     int i;
  201.     mine *mi;
  202.     W_Image *img;
  203.  
  204.     for(i=0;i<MAXPLAYERS * MINESPERPLAYER;i++) {
  205.     if(mines[i].mi_status != MIEMPTY) {
  206.         mi = &mines[i];
  207.         dx = (mi->mi_x >> 4) - cx;
  208.         dy = (mi->mi_y >> 4) - cy;
  209.         if(dx > 0 && 
  210.            dy > 0 &&
  211.            dx < WINWIDTH &&
  212.            dy < WINHEIGHT) {
  213.         if(mines[i].mi_status == MILIVE)
  214.             img = mineImg;
  215.         else
  216.             img = mineExpImg;
  217.         W_DrawImage(cwin, dx - img->width/2, dy - img->height/2,
  218.                 mines[i].mi_fuse, img, W_Red);
  219.         }
  220.         if(mines[i].mi_status == MIEXPLODE) {
  221.         mines[i].mi_fuse++;
  222.         if(mines[i].mi_fuse >= mineExpImg->frames)
  223.             mines[i].mi_status = MIEMPTY;
  224.         }
  225.     }
  226.     }
  227. }
  228.  
  229. void draw_build_marker(int cx, int cy)
  230. {
  231.     int mapx, mapy, dx, dy;
  232.  
  233.     if(me->p_speed == 0 && me->p_trees && showBuildMarker) {
  234.     mapx = (me->p_x >> 4)/GRIDWIDTH;
  235.     mapy = (me->p_y >> 4)/GRIDHEIGHT;
  236.     if(me->p_dir < 32 || me->p_dir > 224)
  237.         mapy--;
  238.     else if(me->p_dir < 96)
  239.         mapx++;
  240.     else if(me->p_dir < 160)
  241.         mapy++;
  242.     else
  243.         mapx--;
  244.     if(mapx < 0 || mapy < 0 || mapx >= map_info.m_width || mapy >= map_info.m_height)
  245.         return;
  246.     dx = mapx*GRIDWIDTH-cx;
  247.     dy = mapy*GRIDHEIGHT-cy;
  248.     W_MakeLine(cwin, dx, dy, dx+GRIDWIDTH-1, dy, W_Yellow);
  249.     W_MakeLine(cwin, dx+GRIDWIDTH-1, dy, dx+GRIDWIDTH-1, dy+GRIDHEIGHT-1, W_Yellow);
  250.     W_MakeLine(cwin, dx, dy+GRIDHEIGHT-1, dx+GRIDWIDTH-1, dy+GRIDHEIGHT-1, W_Yellow);
  251.     W_MakeLine(cwin, dx, dy+GRIDHEIGHT-1, dx, dy, W_Yellow);
  252.     }
  253. }
  254.  
  255. int mapx[MAXPLAYERS], mapy[MAXPLAYERS];
  256.  
  257. void map_square(int x, int y)
  258. {
  259.     W_Color color;
  260.  
  261.     switch(map[x][y]) {
  262.       case T_GRASS:
  263.     color = W_DarkGreen;
  264.     break;
  265.       case T_TREE:
  266.     color = W_Green2;
  267.     break;
  268.       case T_ROAD:
  269.       case T_BRIDGE:
  270.     color = W_Brown;
  271.     break;
  272.       case T_WATER:
  273.     color = W_Blue;
  274.     break;
  275.       case T_CRATER:
  276.     color = W_Yellow;
  277.     break;
  278.       default:
  279.     if(map[x][y] >= T_GWALL && map[x][y] <= T_WALL_TBRL)
  280.         color = W_Red;
  281.     else
  282.         color = W_Grey;
  283.     }
  284.     W_FillArea(mapwin, x*map_pixel, y*map_pixel, map_pixel, map_pixel, color);
  285. }
  286.  
  287. void update_map()
  288. {
  289.     int i,x,y;
  290.     W_Color color;
  291.  
  292.     for(i=0;i<MAXPLAYERS;i++) {
  293.     if(mapx[i] >= 0 && mapy[i] >= 0) {
  294.         map_square(mapx[i], mapy[i]);
  295.     }
  296.     if(players[i].p_status == PALIVE) {
  297.         x = (players[i].p_x >> 4) / GRIDWIDTH;
  298.         y = (players[i].p_y >> 4) / GRIDHEIGHT;
  299.         if(&players[i] == me)
  300.         color = W_White;
  301.         else if(players[i].p_team == 0)
  302.         color = W_Blue;
  303.         else
  304.         color = W_Red;
  305.         W_FillArea(mapwin, x*map_pixel, y*map_pixel, map_pixel, map_pixel, W_White);
  306.         W_MakeLine(mapwin, x*map_pixel, y*map_pixel, 
  307.                x*map_pixel + map_pixel - 1, y*map_pixel + map_pixel - 1, color);
  308. /*
  309.         W_DrawPoint(mapwin, x*2, y*2, W_White);
  310.         W_DrawPoint(mapwin, x*2+1, y*2, W_White);
  311.         W_DrawPoint(mapwin, x*2, y*2+1, color);
  312.         W_DrawPoint(mapwin, x*2+1, y*2+1, color);
  313. */
  314.         mapx[i] = x;
  315.         mapy[i] = y;
  316.     } else {
  317.         mapx[i] = -1;
  318.     }
  319.     }
  320. }
  321.  
  322. void redraw_map()
  323. {
  324.     int x, y;
  325.  
  326.     for(x=0;x<map_info.m_width;x++) {
  327.     for(y=0;y<map_info.m_height;y++) {
  328.         map_square(x,y);
  329.     }
  330.     }
  331.  
  332.     update_map();
  333. }
  334.  
  335. void init_terrain()
  336. {
  337.     int i;
  338.  
  339.     for(i=0;i<NUMTERRAINS;i++)
  340.     t_shapes[i] = getImage(t_image_nums[i]);
  341. }
  342.  
  343. void do_redraw()
  344. {
  345.     int cx, cy;
  346.  
  347.     if(!displayoff) {
  348.     cx = (me->p_x>>4)-WINWIDTH/2;
  349.     cy = (me->p_y>>4)-WINHEIGHT/2;
  350.     if(cx < 0) cx = 0;
  351.     else if(cx > GRIDWIDTH * map_info.m_width - WINWIDTH)
  352.         cx = GRIDWIDTH * map_info.m_width - WINWIDTH;
  353.     if(cy < 0) cy = 0;
  354.     else if(cy > GRIDHEIGHT * map_info.m_height - WINHEIGHT)
  355.         cy = GRIDHEIGHT * map_info.m_height - WINHEIGHT;
  356.     
  357.     draw_local(cx,cy);
  358.     draw_mines(cx, cy);
  359.     draw_shells(cx, cy);
  360.     draw_players(cx,cy);
  361.     draw_overlays(cx,cy);
  362.     draw_flags(cx, cy);
  363.     draw_shell_exps(cx, cy);
  364.     draw_build_marker(cx, cy);
  365.  
  366.     W_DisplayBuffer(cwin);
  367.     W_Flush();
  368.     update_map();
  369.     }
  370. }
  371.